<html>

<!-- Mirrored from introcomputing.org/image-6-exercises.html by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 24 Jan 2019 10:56:45 GMT -->
<head>
<title>Image 6 Exercises</title>
<link rel=stylesheet href=style.css type="text/css">

</head>
<body>
<script type="text/javascript" src="cs101.js"></script>
<script type="text/javascript" src="cs101-table.js"></script>
<script type="text/javascript" src="cs101-simulation.js"></script>

<!-- njp
<div id=warning-output></div>
-->

<h1>Image 6 Exercises</h1>

<p>




<p>
1. Red Golden Gate - the image golden-gate-red.jpg shows the golden gate bridge, but all of the data is in the red  values.


<br><img src="golden-gate-red.jpg" alt="golden gate bridge, shown in red">

<p>
Write code that for each pixel copies the red value over to be the green and blue value. The result will be to change the image to grayscale which will look better.

<p style='max-width:1000'>
<table class=run>
<tr><td valign=top width=550> <!-- CODE -->
<textarea id="image-6-ex1" rows=15 cols=70  class=tacode spellcheck=false
onKeyPress='return handleCR(this ,event)'>
image = new SimpleImage("golden-gate-red.jpg");

for (pixel: image) {
  // your code here
  
}

print(image);</textarea>
<br><input type=button style='width:220;height:40;background-color:lightgray'
value="Run" onClick='evaluateClear("image-6-ex1")'>
</td>
<td valign=top> <!-- OUTPUT -->
<div id='image-6-ex1-output' style="font-family:courier;font-size:14;"></div>
</td></tr>
</table>


<p>
2. Gray Banana - write code to change the banana.jpg image to grayscale.

<br><image src="banana.jpg" alt="a yellow banana">

<p>
Write code to change the banana.jpg image to be grayscale. Reminder: here is the line used in the loop to compute the average of the red/green/blue values and store that value in a variable named "avg".

<pre>
  avg = (pixel.getRed() + pixel.getGreen() + pixel.getBlue())/3;
</pre>


<p style='max-width:1000'>
<table class=run>
<tr><td valign=top width=550> <!-- CODE -->
<textarea id="image-6-ex2" rows=14 cols=70  class=tacode spellcheck=false
onKeyPress='return handleCR(this ,event)'>
image = new SimpleImage("banana.jpg");

for (pixel: image) {
  // your code here
  
}

print(image);</textarea>
<br><input type=button style='width:220;height:40;background-color:lightgray'
value="Run" onClick='evaluateClear("image-6-ex2")'>
</td>
<td valign=top> <!-- OUTPUT -->
<div id='image-6-ex2-output' style="font-family:courier;font-size:14;"></div>
</td></tr>
</table>




</body>

<!-- Mirrored from introcomputing.org/image-6-exercises.html by HTTrack Website Copier/3.x [XR&CO'2014], Thu, 24 Jan 2019 10:56:46 GMT -->
</html>

